package test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class P2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n1, n2, n3, m;
        n1 = sc.nextInt();
        n2 = sc.nextInt();
        n3 = sc.nextInt();
        HashSet<String> subjectMap = new HashSet<>();
        HashSet<String> verbMap = new HashSet<>();
        HashSet<String> objectMap = new HashSet<>();
        List<String> r = new ArrayList<>();
        for (int i = 0; i < n1; i++) {
            subjectMap.add(sc.next());
        }
        for (int i = 0; i < n2; i++) {
            verbMap.add(sc.next());
        }
        for (int i = 0; i < n3; i++) {
            objectMap.add(sc.next());
        }
        m = sc.nextInt();
        sc.nextLine();
        for (int i = 0; i < m; i++) {
            String s = sc.nextLine();
            String[] s1 = s.split(" ");
            boolean subject = false;
            boolean verb = false;
            boolean valid = true;
            for (int j = 0; j < s1.length; j++) {
                String cur = s1[j];
                // 找到主语
                if (subjectMap.contains(cur)) subject = true;
                // 有谓语了还来谓语或者主语
                if (verb && (subjectMap.contains(cur) || verbMap.contains(cur))) {
                    valid = false;
                }
                //没有主语 就有谓语了
                if (!subject && verbMap.contains(cur)) {
                    valid = false;
                }
                //没有主谓语就有宾语
                if (objectMap.contains(cur) && (!subject || !verb)) {
                    valid = false;
                }
                if (subjectMap.contains(cur)) {
                    subject = true;
                }
                if (verbMap.contains(cur)) {
                    verb = true;
                }
                if (!valid) break;
            }
            valid = valid && subject && verb;
            //System.out.println(valid ? "YES" : "NO");
            r.add(valid == true? "YES": "NO");
        }
        for (int i = 0; i < r.size(); i++) {
            System.out.println(r.get(i));
        }
    }
}
